package com.itheima.pinda.authority.controller.common;

import com.itheima.pinda.authority.entity.common.Area;
import com.itheima.pinda.authority.feign.AreaFeign;
import com.itheima.pinda.base.R;
import io.netty.util.internal.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/area")
public class AreaController{
    @Autowired
    AreaFeign areaFeign;

    @GetMapping({"/{id}"})
    R<Area> get(@PathVariable Long id){
        R<Area> result =new R<Area>();
        result.setData(areaFeign.getArea(id));
        return result;
    }

    @GetMapping({"/code/{code}"})
    R<Area> getByCode(@PathVariable String code){
        if(StringUtil.isNullOrEmpty(code)){
            return null;
        }
        return areaFeign.getByCode(code);
    }

    @GetMapping
    R<List<Area>> findAll(@RequestParam(value = "parentId",required = false) Long parentId, @RequestParam(value = "ids",required = false) List<Long> ids){

        return areaFeign.findAll(parentId,ids);
    }
}
